//
//  WithdrawPointsController.m
//  LianShangBao
//
//  Created by 主事丫环HU on 2020/9/8.
//  Copyright © 2020 主事丫环. All rights reserved.
//

#import "WithdrawPointsController.h"
#import "WithdrawPointsCell.h"
#import "WithdrawPointsListModel.h"
@interface WithdrawPointsController ()
@property (weak, nonatomic) IBOutlet UILabel *integralLabel;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *dataArray;
@end

@implementation WithdrawPointsController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    self.dataArray = [NSMutableArray arrayWithCapacity:0];
    [self requestIntegralListData];
}
- (void)setupUI{
    self.integralLabel.text = self.outIntegral;
    self.tableView.rowHeight = 60;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self setTableViewSeperaInsetZero];
}
- (void)requestIntegralListData{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"userId"] = USER_ID;
    [MBProgressHUD showHUDAddedTo:self.view  animated:YES];
    [NetWorkTool POST:integralWithdrawList param:param success:^(id dic) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        self.dataArray = [WithdrawPointsListModel mj_objectArrayWithKeyValuesArray:dic[@"data"]];
        [self.tableView reloadData];
    } other:^(id dic) {
        ShowToastWithText(dic[@"msg"]);
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    } fail:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    } needUser:YES];
}
#pragma mark -- UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   return self.dataArray.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    WithdrawPointsListModel *model = self.dataArray[indexPath.row];
    WithdrawPointsCell *cell = [WithdrawPointsCell cellWithTableView:tableView];
    cell.model = model;
    return cell;
    
}
// cell的分割线顶格
- (void)setTableViewSeperaInsetZero{
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}
- (IBAction)backButtonClick:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
